<?php
    $ss_id = $_POST['ss_id'];
    $product_code = addslashes($_POST['product_code']);
    $product_name = addslashes($_POST['product_name']);
    $product_volume = addslashes($_POST['product_volume']);
    $product_diamater = addslashes($_POST['product_diamater']);
    $product_height = addslashes($_POST['product_height']);
    $product_lenght = addslashes($_POST['product_lenght']);
    $product_width = addslashes($_POST['product_width']);
    
    $sql = "UPDATE standard_shape SET ss_code='$product_code',ss_name='$product_name',ss_volume='$product_volume',ss_diamater='$product_diamater',ss_height='$product_height',ss_width='$product_width',ss_lenght='$product_lenght' WHERE ss_id=$ss_id";
    $result = $db->Execute($sql);
    
    if($result){
        $msg = 'บันทึกข้อมูลเรียบร้อยแล้ว';
        if($_FILES['img']['name']!='')
        {
            $handle = new Upload($_FILES['img']);
            if ($handle->uploaded)
            {
                $handle->image_resize = true;
                $handle->image_ratio_fill = true;
                $handle->image_background_color = '#ffffff';
                $handle->image_x = 130;
                $handle->image_y = 120;
                $handle->Process(APPPATH.'/images/standard-shape/'.$ss_id);
    
                if ($handle->processed)
                {
                    $sql = 'UPDATE standard_shape SET ss_img="'.$handle->file_dst_name.'" WHERE ss_id='.$ss_id;
                    $result =$db->Execute($sql);
                    if($result)
                    {
                        if(img_exists(APPPATH.'/images/standard-shape/'.$ss_id,$_POST['img_old'])){
                            @unlink(APPPATH.'/images/standard-shape/'.$ss_id.'/'.$_POST['img_old']);
                        }
                        $msg = 'บันทึกข้อมูลเรียบร้อยแล้ว';
                    }
                    else
                    {
                        if(img_exists(APPPATH.'/images/standard-shape/'.$ss_id,$handle->file_dst_name)){
                            @unlink(APPPATH.'/images/standard-shape/'.$ss_id.'/'.$handle->file_dst_name);
                        }
                        $msg = 'ไม่สามารถอัพโหลดรูปได้';
                    }
                }
                else
                {
                    $msg = 'ไม่สามารถอัพโหลดรูปได้';
                }
    
            }
            else
            {
                $msg = 'ไม่สามารถอัพโหลดรูปได้';
            }
        }
    }else{
        $msg = 'ไม่สามารถบันทึกข้อมูลได้';
    }
?>

<?php
    include('header.php');
    include('submenu.php');
?>
<div class="grid_18" id="contents">
    <div id="query_result">
    <?php
        echo $msg , ' <img src="images/ajax-loader.gif" />';
        redirect("?m=shape-size&s=product-edit&ss_id=$ss_id",3);
    ?>
    </div>
</div><!-- end .grid_18 -->
<div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>